home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13791 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.tu-chemnitz.de!news
  2. From: hfst@hrz.tu-chemnitz.de (Hans Steffani)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: A weird thing about printf()
  5. Date: 10 Apr 96 10:46:09 GMT
  6. Organization: University of Technology Chemnitz, FRG
  7. Message-ID: <4kg3k8$ncn@narses.hrz.tu-chemnitz.de>
  8. References: <4kflr2$5if@dewey.csun.edu>
  9. NNTP-Posting-Host: sisyphus.hrz.tu-chemnitz.de
  10.  
  11. kc44097@csun.edu (chen) writes:
  12.  
  13. >#include <stdio.h>
  14.  
  15. >int answer;
  16. >main()
  17. >{
  18. >  answer=2+2;
  19. >  printf("The answer is %d\n");
  20. >  return 0;
  21. >}
  22.  
  23. >  In printf(),I lost "answer" in the end,but it works,and give me the
  24. >result 0.I wonder how the compiler handle this condition.Also,is this
  25. >allow by C?(by this, I mean is this a leagal usage in language itself,
  26. >or just a mistake cause by the compiler?)
  27.  
  28. The printf() does not know that there is one argument missing.
  29. Therefore it handles in its normal way. Assuming stack passing
  30. it takes some random value from the stack as its 2nd argument.
  31.  
  32. h.f.s.
  33. --
  34. Hans Friedrich Steffani
  35. Institut fuer Elektrische Maschinen und Antriebe
  36. TU Chemnitz-Zwickau
  37. e-mail: hans.steffani@e-technik.tu-chemnitz.de
  38.